//-----------------------------------------------------------
//
//-----------------------------------------------------------
class HUDEnyara extends HUDBase;

var texture e_crosshair
            ,e_empty
            ,e_health
            ,e_Mana
            ,e_levitate
            ,e_shield
            ,e_fireball;
var Font e_font;

var texture MouseCursorTexture, TargetCursorTexture;         //texture to be used for mouse cursor
var float XPos, YPos;
var SpriteWidget MouseCursor, healthWidget, manaWidget, emptyWidget;
var float LastManaPickupTime;


// Constantly called throughout to render HUD.
// The canvas is our screen, we draw to this and we can retrieve
// information from it such as the screen size.
function PostRender( canvas C )
{
    super.PostRender(c);
    if(Level.Pauser==None){
    // Only draw if the player exists (spawned), we dont to before.
    if( Level.GetLocalPlayerController().Pawn != none)
    {
        // Set the draw color, I want white font.
        c.DrawColor.R = 255;
        c.DrawColor.G = 255;
        c.DrawColor.B = 255;

        // Set the font to use.
        c.Font = e_font;

        //DrawCrosshair(c);
        c.SetPos(c.SizeX-256,c.SizeY-128);
        DrawEmpty(c);
        DrawHealth(c);
        DrawMana(c);
        DrawWeapon(c);
        //DrawToolTip(c);
    }

   EnyaraPlayerController(PlayerOwner).LastHUDSizeX = C.SizeX;
   EnyaraPlayerController(PlayerOwner).LastHUDSizeY = C.SizeY;


      if(PlayerOwner.IsInState('PlayerMousing'))
      {
            DrawMouseCursor(C);
            //if(String(EnyaraPlayerController(Level.GetLocalPlayerController()).HitActor.Tag) == "LevelInfo"){
            //}else{
            //    DrawToolTip(c);
            //}
      }
   }
}

function DrawToolTip(Canvas Canvas)
{
         //Canvas.SetPos(200,200);
         Canvas.DrawText(EnyaraPlayerController(Level.GetLocalPlayerController()).HitActor.Name);
}

// Draw the crosshair in centre of screen.
function DrawCrosshair(Canvas Canvas)
{
    // Only draw if the weapon exists, if no weapon, no crosshair.
    if (Level.GetLocalPlayerController().Pawn.Weapon != none)
    {
        // SizeX returns size of screen so from that we work out
        // the centre of screen in X and Y.
        Canvas.SetPos((canvas.SizeX/2)-32,canvas.SizeY/2-32);
        Canvas.DrawIcon(e_crosshair,1.0);
    }
}

// Draw the health on the screen, icon and text value.
function DrawHealth(Canvas Canvas)
{
    // Draw the health icon, 64pixels square so I want it in the
    // bottom left, 10X and 10 up from the bottom Y. 1.0 when drawing
    // the icon is the scale (2.0 would be twice size etc).
    //Canvas.SetPos(10,canvas.SizeY-74);

    local float h,drawStart;
    //h = Level.GetLocalPlayerController().Pawn.Health / Level.GetLocalPlayerController().Pawn.HealthMax;
    h = EnyaraPlayerController(PlayerOwner).Pawn.Health / EnyaraPlayerController(PlayerOwner).Pawn.HealthMax;
    drawStart = Round(1500-1500*h);  //determine percentage of health bar to draw based on Pawn health percentage
    healthWidget.TextureCoords.X1=drawStart;

    healthWidget.WidgetTexture=e_health;
    DrawSpriteWidget(Canvas,healthWidget);

    /*
    // Draw the health text, retrieve this from the player.
    Canvas.SetPos(84,canvas.SizeY-64);
    Canvas.DrawText(Level.GetLocalPlayerController().Pawn.Health);
    */
}

// Draw the health on the screen, icon and text value.
function DrawEmpty(Canvas Canvas)
{
    // Draw the health icon, 64pixels square so I want it in the
    // bottom left, 10X and 10 up from the bottom Y. 1.0 when drawing
    // the icon is the scale (2.0 would be twice size etc).
    //Canvas.SetPos(10,canvas.SizeY-74);

    //Canvas.SetPos(canvas.sizeX-512,canvas.sizey-256);
    //Canvas.DrawIcon(e_empty,0.25);

    //emptyWidget.PosX=(128);
    //emptyWidget.PosY=(Canvas.SizeY-128);
    emptyWidget.WidgetTexture=e_empty;
    DrawSpriteWidget(Canvas,emptyWidget);

}

// Draw the ammo on the screen, icon and text value.
function DrawMana(Canvas Canvas)
{

    local float m,drawStart;
    //m = Level.EnyaraPlayerController(GetLocalPlayerController()).Mana / Level.EnyaraPlayerController(GetLocalPlayerController()).ManaMax;
    m = float(EnyaraPlayerController(PlayerOwner).Mana) / float(EnyaraPlayerController(PlayerOwner).ManaMax);
    drawStart = Round(1168-1168*m);  //determine percentage of mana bar to draw based on player mana percentage
    manaWidget.TextureCoords.X1=drawStart;



    manaWidget.WidgetTexture=e_mana;
    DrawSpriteWidget(Canvas,manaWidget);


    //local float current_Mana;
    /*
    local int Mana;
    // Draw icon in bottom right
    Canvas.SetPos(canvas.SizeX-74,canvas.SizeY-74);
    Canvas.DrawIcon(e_Mana,1.0);

    // Only display ammo amount if a weapon exists.

    if (Level.GetLocalPlayerController().Pawn.Weapon != none)
    {
        // Retrieve the ammo ammount from the players weapon.
        Mana = EnyaraPlayerController(Level.GetLocalPlayerController()).Mana;

        //Mana = current_Mana;

        // Draw the amount of ammo
        Canvas.SetPos(canvas.SizeX-174,canvas.SizeY-64);
        Canvas.DrawText(Mana);
    }
    */
}

function DrawWeapon(Canvas Canvas)
{
    //local float current_Mana;
    local String Weap;

    // Only display ammo amount if a weapon exists.

    if (Level.GetLocalPlayerController().Pawn.Weapon != none)
    {
        // Retrieve the ammo ammount from the players weapon.
        Weap = EnyaraPlayerController(Level.GetLocalPlayerController()).Pawn.Weapon.ItemName;

         // Draw icon in center bottom
          Canvas.SetPos(0,canvas.SizeY-64);

          if(Weap == "Levitate"){
             Canvas.SetPos(0,0);
             Canvas.DrawIcon(e_levitate,0.35);
          }else if(Weap == "Fireball"){
             Canvas.SetPos(0,0);
             Canvas.DrawIcon(e_fireball,0.35);
          }else if(Weap == "Element Shield"){
             Canvas.SetPos(0,0);
             Canvas.DrawIcon(e_shield,0.35);
          }else{
                Canvas.DrawText(Weap);
          }
    }
}

function DrawMouseCursor(Canvas C)
{
    C.SetDrawColor(255,255,255);
    C.Style = ERenderStyle.STY_Alpha;

    EnyaraPlayerController(PlayerOwner).PlayerMouse.X = PlayerOwner.Player.WindowsMouseX;
    EnyaraPlayerController(PlayerOwner).PlayerMouse.Y = PlayerOwner.Player.WindowsMouseY;

    // render mouse cursor
    XPos = EnyaraPlayerController(PlayerOwner).PlayerMouse.X / C.SizeX;
    YPos = EnyaraPlayerController(PlayerOwner).PlayerMouse.Y / C.SizeY;

    MouseCursor.PosX = XPos;
    MouseCursor.PosY = YPos;

    if(EnyaraPlayerController(PlayerOwner).isTargeting || String(EnyaraPlayerController(PlayerOwner).HitActor.Tag) == "EnferiPawn"){
       MouseCursor.WidgetTexture = TargetCursorTexture;
       MouseCursor.OffsetX=-64;
       MouseCursor.OffsetY=-64;
    }
    else {
       MouseCursor.WidgetTexture = MouseCursorTexture;
       MouseCursor.OffsetX=0;
       MouseCursor.OffsetY=0;
    }
    DrawSpriteWidget(C, MouseCursor);
    if(EnyaraPlayerController(Level.GetLocalPlayerController()).HitActor != none &&
      (String(EnyaraPlayerController(Level.GetLocalPlayerController()).HitActor.Tag) == "LevelInfo" ||
       String(EnyaraPlayerController(Level.GetLocalPlayerController()).HitActor.Tag) == "TerrainInfo" ||
       String(EnyaraPlayerController(Level.GetLocalPlayerController()).HitActor.Tag) == "None")){
      }else{
          C.SetPos(C.CurX, C.CurY+70);
          C.FontScaleX=0.50;
          C.FontScaleY=0.50;
          DrawToolTip(C);
      }

    //C.SetPos(XPos, YPos);
    //C.DrawIcon(MouseCursorTexture, 1);

    return;
}

// Load the textures and font.
defaultproperties
{
    e_crosshair = texture'EnyaraTextures.HUD.Crosshair'
    e_empty = texture'EnyaraTextures.HUD.hud-empty'
    e_health = texture'EnyaraTextures.HUD.hud-life'
    e_Mana = texture'EnyaraTextures.HUD.hud-mana'
    e_font = font'UT2003Fonts.jFontLarge800x600'
    e_levitate = texture'EnyaraTextures.Spells.levitate'
    e_shield = texture'EnyaraTextures.Spells.Shield'
    e_fireball = texture'EnyaraTextures.Spells.fireball'

    //MouseCursorTexture=Texture'2K4Menus.Cursors.Pointer'
    MouseCursorTexture=Texture'EnyaraTextures.Cursors.mc_medium'
    TargetCursorTexture=Texture'EnyaraTextures.Cursors.tc_medium'

    MouseCursor=(RenderStyle=STY_Alpha,TextureCoords=(X2=128,Y2=128),TextureScale=0.25,OffsetX=0,OffsetY=0,DrawPivot=DP_UpperLeft,PosX=0.0,PosY=0.0,Scale=1.000000,Tints[0]=(B=255,G=255,R=255,A=255))
    emptyWidget=(RenderStyle=STY_Alpha,TextureCoords=(X2=2048,Y2=1024),TextureScale=0.125,OffsetX=0,OffsetY=0,DrawPivot=DP_UpperRight,PosX=1,PosY=-0.045,Scale=1.000000,Tints[0]=(B=255,G=255,R=255,A=255))
    healthWidget=(RenderStyle=STY_Alpha,TextureCoords=(X2=1500,Y2=1024),TextureScale=0.125,OffsetX=0,OffsetY=0,DrawPivot=DP_UpperRight,PosX=0.895,PosY=-0.045,Scale=1.000000,Tints[0]=(B=255,G=255,R=255,A=255))
    manaWidget=(RenderStyle=STY_Alpha,TextureCoords=(X2=1168,Y2=1024),TextureScale=0.125,OffsetX=0,OffsetY=0,DrawPivot=DP_UpperRight,PosX=0.83,PosY=-0.045,scale=1.000000,Tints[0]=(B=255,G=255,R=255,A=255))

}

